﻿<%@ Page Title="Classes" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Classes.aspx.cs" Inherits="Testify.Courses.Classes" %>
<%@ MasterType VirtualPath="~/Site.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            $("#MainContent_gv_students").show(400);
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="container">
        <asp:SqlDataSource ID="src_classes" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
            SelectCommand="SELECT s.section_id as section_id, crst.course_type_prefix || ' ' || crs.course_number || '-' || s.section_number || ': ' || crs.course_name AS course_fancy, 
                                (SELECT count(student_id) from enrollment where section_id = s.section_id) as scount
                           FROM section s
                           JOIN class cls ON cls.class_id = s.class_id
                           JOIN course crs ON crs.course_id = cls.course_id
                           JOIN course_type crst ON crst.course_type_id = crs.course_type_id
                          WHERE s.teacher_id = :p_TeacherID AND s.section_maint != 'D'
                            AND cls.term_id = (SELECT current_term_id FROM environment)">
            <SelectParameters>
                <asp:SessionParameter Name="p_TeacherID" SessionField="UserID" />
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:GridView ID="gv_classes" runat="server" AutoGenerateColumns="False" DataKeyNames="section_id"
            DataSourceID="src_classes" SelectedRowStyle-BorderStyle="None" 
            EmptyDataText="You have no classes." onrowcommand="gv_classes_RowCommand">
            <Columns>
                <asp:BoundField DataField="COURSE_FANCY" HeaderText="Class" 
                    SortExpression="COURSE_FANCY" />
                <asp:BoundField DataField="scount" HeaderText="Students" 
                    SortExpression="COUNT(E.STUDENT_ID)" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Button ID="btn_showStudents" CssClass="btn_details" CommandArgument='<%# Bind("section_id") %>' runat="server" CausesValidation="false" CommandName="showStudents" Text="Details" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <SelectedRowStyle BorderStyle="None"></SelectedRowStyle>
        </asp:GridView>

        <asp:SqlDataSource ID="src_students" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
            SelectCommand="SELECT user_id, user_first_name, user_first_name || ' ' || user_last_name as name
                           FROM testify_user t
                           JOIN enrollment e ON e.student_id = t.user_id
                           WHERE e.section_id = :p_SectionID AND t.user_type_id = 3 AND user_maint != 'D'">
            <SelectParameters>
                <asp:ControlParameter ControlID="gv_classes" Name="p_SectionID" PropertyName="SelectedValue" />
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:GridView ID="gv_students" runat="server" DataSourceID="src_students" CssClass="hidden"
            AutoGenerateColumns="False" DataKeyNames="USER_ID" RowStyle-HorizontalAlign="Left">
            <Columns>
                <asp:BoundField DataField="NAME" HeaderText="Class Roster" SortExpression="USER_FIRST_NAME" />
            </Columns>
        </asp:GridView>
    </div>
</asp:Content>
